﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using HZ.Supervise.Model;
using HZ.Supervise.IBLL;

public partial class EarlyWarning_WarningTradProcessStop : BasePage
{
    public EarlyWarning_WarningTradProcessStop()
    { }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGridView();
        }
    }

    private void BindGridView()
    {
        int t = 0;
        HZ.Supervise.IBLL.IBLL_PreWarning warning = HZ.Supervise.BLLFactory.IBLL_PreWarning();
        HZ.Supervise.Model.TradePreWarning preWarning = new HZ.Supervise.Model.TradePreWarning();
        preWarning.IsUsing = false;
        System.Data.DataTable dt = warning.GetTradePreWarning(preWarning, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                if (row["HospitalID"].ToString() != "所有医院" && row["HospitalName"] == DBNull.Value)
                {
                    row["Hospitalname"] = "多家医院";
                }
                if (row["CompanyId_PS"].ToString() != "所有企业" && row["CompanyName"] == DBNull.Value)
                {
                    row["CompanyName"] = "多家企业";
                }
                if (row["WarningType"] != DBNull.Value)
                {
                    if (row["WarningType"].ToString() == "2")
                    {
                        row["CompanyName"] = "无需企业";
                    }
                }
            }
        }
        AspNetPager1.RecordCount = t;
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    /// <summary>
    /// 开启预警
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_openWarning_Click(object sender, EventArgs e)
    {
        if (this.GridView1.Rows.Count > 0)
        {
            string id = Request["checkbox1"];
            if (!string.IsNullOrEmpty(id))
            {
                HZ.Supervise.Model.TradePreWarning Trade = new TradePreWarning();
                HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                string[] arraryIds = id.Split(',');
                foreach (string Item in arraryIds)
                {
                    Trade.TradePreWarningID = Item;
                    Trade.IsUsing = true;
                    int n = pre.UpdateTradePreWarning(Trade);
                }
                HZ.Web.WebUtil.Alert("启用成功！");
            }
            else
            {
                HZ.Web.WebUtil.Alert("请选择后在启用！");
            }
        }

        BindGridView();
    }

    /// <summary>
    /// 删除预警
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_delWarning_Click(object sender, EventArgs e)
    {
        if (this.GridView1.Rows.Count > 0)
        {
            string id = Request["checkbox1"];
            if (!string.IsNullOrEmpty(id))
            {
                HZ.Supervise.Model.TradePreWarning drugwar = new TradePreWarning();
                HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                string[] arraryIds = id.Split(',');
                foreach (string Item in arraryIds)
                {
                    drugwar.TradePreWarningID = Item;
                    drugwar.IsUsing = false;
                    int n = pre.DeleteTradePreWarning(drugwar);
                }
            }
            else
            {
                HZ.Web.WebUtil.Alert("请选择后在删除！");
            }
        }

        BindGridView();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label LabType = (Label)e.Row.FindControl("LabType");
            Label LabLeve = (Label)e.Row.FindControl("LabLeve");

            switch (LabType.Text)
            {
                case "0":
                    LabType.Text = "医院已提交采购单企业未确认";
                    break;
                case "1":
                    LabType.Text = "企业已确认定单医院未入库";
                    break;
                case "2":
                    LabType.Text = "企业已开发票中心未审核";
                    break;
                case "3":
                    LabType.Text = "医院已提交退货单企业未确认";
                    break;
                case "4":
                    LabType.Text = "医院已提交回款单企业未确认";
                    break;
                case "5":
                    LabType.Text = "医院已入库未回款";
                    break;
            }

            switch (LabLeve.Text)
            {
                case "1":
                    LabLeve.Text = "一级预警";
                    break;
                case "2":
                    LabLeve.Text = "二级预警";
                    break;
                case "3":
                    LabLeve.Text = "三级预警";
                    break;
            }

            string _AreaID = ((DataRowView)e.Row.DataItem).Row.ItemArray[1].ToString();
            string _HospitalID = ((DataRowView)e.Row.DataItem).Row.ItemArray[4].ToString();
            string _CompanyId = ((DataRowView)e.Row.DataItem).Row.ItemArray[5].ToString();

            e.Row.Cells[2].Attributes.Add("onclick", "javascript:window.open('showHospital.aspx?HospitalID=" + Server.UrlEncode(_HospitalID) + "&&AreaID=" + Server.UrlEncode(_AreaID) + "','showHospital1','width=600,height=400,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0')");
            e.Row.Cells[3].Attributes.Add("onclick", "javascript:window.open('showCompany.aspx?CompanyID=" + Server.UrlEncode(_CompanyId) + "','showCompany','width=600,height=400,resizable=0,scrollbars=0, status=0, toolbar=0, menubar=0')");

            e.Row.Cells[2].Attributes.Add("onmouseover", "this.style.color='red'");
            e.Row.Cells[2].Attributes.Add("onmouseout", "this.style.color=''");

            e.Row.Cells[3].Attributes.Add("onmouseover", "this.style.color='red'");
            e.Row.Cells[3].Attributes.Add("onmouseout", "this.style.color=''");
        }
    }
}
